import Vue from 'vue'
//1.导入路由类
import VueRouter from 'vue-router'
// 2.导入组件
import Login from '@/components/Login.vue'
import Home from '@/components/Home.vue'
import Welcome from '@/components/Welcome.vue'
import Users from '@/components/user/Users.vue'
// import Rights from '@/components/power/Rights.vue'
// 3.注册全局路由组件
Vue.use(VueRouter)
// 4.创建路由规则
const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name:'Login',
        component:Login
    },
        {
        path: '/home',
        name:'Home',
        component: Home,
        redirect: '/welcome',
        children: [
            {
            path: '/welcome',
            component:Welcome
            },
            {
            path: '/users',
            component:Users
            },
            {
            path: '/rights',
            component:()=>import('@/components/power/Rights.vue')
            },
            {
                path: '/roles',
                component:()=>import('@/components/power/Roles.vue')
            },
            {
                path: '/categories',
                component:()=>import('@/components/goods/Cate.vue')
            },
            {
                path: '/params',
                component:()=>import('@/components/goods/Params.vue')
            },
            {
                path: '/goods',
                component: () => import('@/components/goods/List.vue'),
              
            },
            {
                path: '/goods/add',
                component:()=>import('@/components/goods/Add.vue')
            },
            {
                path: '/orders',
                component:()=>import('@/components/order/Order.vue')
            },
            {
                path: '/reports',
                component:()=>import('@/components/report/Report.vue')
            }
            ]
        }
]
// 5.创建路由实例
const router = new VueRouter({
    routes
})
// 路由守卫
router.beforeEach((to, from, next) => {
    if(to.path === '/login') return next()
    const tokenStr = window.sessionStorage.getItem('token')
    if (!tokenStr) return next('/login')
    next()
})
// 5.创建并导出路由管理器对象
export default router
// new VueRouter({
//     routes
// })